package com.marvin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.marvin.core.BlogCategory;
import com.marvin.mapper.BlogCategoryMapper;
import com.marvin.service.IBlogCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author yinyin
 * @create 2021/11/14 下午 4:57
 */
@Service
public class BlogCategoryImpl extends ServiceImpl<BlogCategoryMapper,BlogCategory> implements IBlogCategoryService {
    @Override
    public List<BlogCategory> findBlogCategory() {
        LambdaQueryWrapper<BlogCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlogCategory::getStatus, 1);
        List<BlogCategory> blogCategoryList = this.list(queryWrapper);
        //排序
        if (!CollectionUtils.isEmpty(blogCategoryList)){
            blogCategoryList= blogCategoryList.stream().sorted((a,b)->
                a.getSorted()-b.getSorted()
            ).collect(Collectors.toList());
        }
        return blogCategoryList;
    }
}
